package mystack;

public class ArrayStack {
    private String[]  items;
    private int count;//栈中元素个数
    private int n;//栈的大小

    public ArrayStack(int n) {
        this.items=new String[n];
        this.count=0;
        this.n = n;
    }
    public boolean push(String item){
        if(count==n){
         return false;
        }
        this.items[count]=item;
        this.count++;
        return true;
    }

    public String pop(){
        if(count==0){
            return null;
        }
        String tmp=items[count-1];
        count--;
        return tmp;
    }

    public void print(){
        int i=0;
        while (i<count){
            System.out.print(items[i]);
            System.out.print(",");
            i++;
        }
    }

    public static void main(String[] args) {
        ArrayStack stack = new ArrayStack(10);
        stack.push("a");
        stack.push("b");
        stack.push("c");
        stack.push("d");
        stack.print();
        System.out.println();
        System.out.println(stack.pop());
    }
}
